package com.sinothk.gpserver.modules.biz.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sinothk.gpserver.modules.biz.entity.GroupMemberEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sinothk.gpserver.modules.biz.entity.GroupMemberDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * <p>
 * 俱乐部成员相关 Mapper 接口
 * </p>
 *
 * @author Liang Y.t.
 * @since 2021-08-29
 */
@Mapper
@Repository
public interface GroupMemberMapper extends BaseMapper<GroupMemberEntity> {

    @Select("SELECT u.*, gm.group_id as group_id, gm.group_role as group_role, gm.member_coins as member_coins  FROM sys_user u LEFT JOIN biz_group_member gm ON u.account = gm.member_account WHERE gm.deleted=0 AND gm.group_id = '${groupId}' ORDER BY gm.group_role DESC, gm.create_time ASC")
    IPage<GroupMemberDto> pageForGroupId(Page<GroupMemberEntity> page, String groupId);

    @Select("SELECT u.*, gm.group_id as group_id, gm.group_role as group_role, gm.member_coins as member_coins FROM sys_user u LEFT JOIN biz_group_member gm ON u.account = gm.member_account WHERE gm.deleted=0 AND gm.group_id = '${groupId}' AND gm.invite_by = '${inviteBy}' ORDER BY gm.group_role DESC, gm.create_time ASC")
    IPage<GroupMemberDto> pageGroupMemberForInviterId(Page<GroupMemberEntity> page, String groupId, String inviteBy);
}
